#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : jarry

import sys
import os
import logging
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    import maya.mel as mel
    import pymel.core as pm
    import jarryLibs.mayakit.MayaUtils as mu

    reload(mu)
except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class CheckAudioExists(CheckBase):
    def __init__(self):
        super(CheckAudioExists, self).__init__()

    def get_sound_node(self):
        gPlayBackSlider = mel.eval('$tmpVar=$gPlayBackSlider')
        sound = cmds.timeControl(gPlayBackSlider, q=True, sound=1)
        return sound

    def check(self):
        sound = self.get_sound_node()
        if sound:
            sound_file = cmds.getAttr('%s.filename' % sound)
            if not os.path.exists(sound_file):
                result_log = u'Error:%s这个文件找不到！\n' % sound_file
            else:
                result_log = u'Succeed:没有问题\n'
        else:
            result_log = u'Warning:当前文件内没有找到指定的声音节点\n'

        # if result_proc:
        #     result_log = u'Error:%s\n' % result_proc
        # else:
        #     result_log = u'Succeed:没有问题\n'

        return result_log

    def fix(self):
        pass